﻿using System;
using System.Linq;
using System.Net;

namespace AIC_Notification
{
    public class StudentStatusReportForStudent : StudentStatusReportForAC
    {
        private int City;
        private string CityName;

        public StudentStatusReportForStudent()
        {
            ReportTitle = "Student Status (Student)";
            StatisticsLabel = "O";
            ShowStatistics = false;
            ShowURL = false;
            SortAscending = false;
            ShowFullTable = DisplayTable.partial;
            DisplayScore = false;
        }

        public override string GenerateLedger()
        {
            string htmlLedger = "";

            htmlLedger += "<tr><td>";

            htmlLedger += "<table align=\"center\" style=\"margin-left:auto; margin-right: auto; border: 0px solid black; border-collapse: collapse;\"><tr>";
            htmlLedger += "<td style=\"font-size: 12px; background-color: #F8D3D3;\">Red:  2 or more drafts from goal </td>";
            htmlLedger += "<td style=\"font-size: 12px; background-color: #FFFFCC;\">Yellow:  ~1 draft from goal </td>";
            htmlLedger += "<td style=\"font-size: 12px; background-color: #CCFFCC;\">Green: Met goal</td>";
            htmlLedger += "</tr></table>";

            htmlLedger += "<div style=\"text-align:center; font-size: 11px;\"><b><u>Student Essay Status</u></b>:<b>/R</b> = Has Revision; <b>/F</b> = Finalized</div> ";
            htmlLedger += "<div style=\"text-align:center; font-size: 11px;\">";
            htmlLedger += "<b><u>Completion Calculation</u></b>: <b>CEF</b>= only CER is counted, not CEF; <b>HAL</b> = Only HAL is counted, not MAJ.";
            htmlLedger += "</div>";
            htmlLedger += "</td></tr>";

            return htmlLedger;
        }

        public override string SetSortOrder(SOF_Application student)
        {
            if (student.StudentObject != null)
                return String.Format("{0:00.0}-{1}", student.ApplicationStats.ProgressScore, student.StudentObject.Nickname);
            else
                return String.Format("{0:00.0}-{1}", student.ApplicationStats.ProgressScore, "");
        }

        public override string InsertStudentName(AIC_Application student, int FontSize, string BackgroundColor = "", int RowSpan = 1)
        {
            string tableBody = "";
            string NickNameHTML;

            if (student.StudentObject != null)
            {
                if (student.StudentObject.Nickname != "")
                    NickNameHTML = String.Format("<div style=\"font-size: {1}px;\">{0}</div>", WebUtility.HtmlEncode(student.StudentObject.Nickname), FontSize);
                else
                    NickNameHTML = "<div style=\"color: white;\">-</div>";
            }
            else
            {
                NickNameHTML = "<div style=\"color: white;\">-</div>";
            }

            tableBody += "<td><div>";
            tableBody += String.Format("<div><div style=\"color: white;\">-</div>{0}<div style=\"color: white;\">-</div></div>", NickNameHTML);
            tableBody += "</div></td>";

            return tableBody;
        }

        public override void SendReportAsEmail()
        {
            for (int i = 0; i < CityDB.NoOfCities; i++)
            {
                string HTMLBody;

                // Only for office with 1 or more student
                if (CityDB.Cities[i].Students.Count() > 0)
                {
                    City = i;
                    CityName = CityDB.GetCityName((CityDB.CityEnum)i);

                    Students = CityDB.Cities[i].Students;
                    RallySchoolStatsList = CityDB.Cities[i].RallySchoolStatsList;
                    RallyOfRallySchoolStats = CityDB.Cities[i].RallyOfRallySchoolStats;
                    HeaderInformation = CityName;

                    FileName = String.Format("{0}-{1}-{2:yyyyMMdd-HHmmss}.htm", ReportTitle, CityName, Global.Now());
                    Global.SysUtil.Log("Generating Report: " + FileName);

                    HTMLBody = GetHTMLBody();

                    // Save Report to File
                    SaveReportToFile(FileName, HTMLBody);

                    // Send Report E-mail
                    toRecipients.Clear();
                    ccRecipients.Clear();

                    toRecipients.Add(CityDB.GetCityServiceGroupEmail((CityDB.CityEnum)i));

                    string[] SystemAdmins = TeacherDB.GetSystemAdmin();
                    foreach (var SystemAdmin in SystemAdmins)
                        ccRecipients.Add(SystemAdmin);

                    SubjectID = CityName;
                    Global.SysUtil.SendHTML(toRecipients, ccRecipients, GetSubject(), HTMLBody);
                }
            }
        }
    }
}
